package cst.a305htr.recyclertest305htr;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.LinearLayout;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    private RecyclerView recyclerView;
    private RecyclerView.LayoutManager layoutManager;
    private MyAdapter mAdapter;
    List<ArticleBean> list;
    private void initRecyclerView(){
        recyclerView = (RecyclerView)findViewById(R.id.recycleview);
        layoutManager = new LinearLayoutManager(this);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setHasFixedSize(true);
        list = getData();
        mAdapter = new MyAdapter(this);
        mAdapter.setList(list);
        recyclerView.setAdapter(mAdapter);
}

    private List<ArticleBean> getData() {
        List<ArticleBean> list = new ArrayList<ArticleBean>();
        ArticleBean art;
        int i;
        for(i=0;i<6;i++) {
            art = new ArticleBean();
            art.setArticleId(1);
            art.setTitle("标题"+i);
            if(i==0) art.setImgid(R.drawable.f1);
            if(i==1) art.setImgid(R.drawable.f2);
            if(i==2) art.setImgid(R.drawable.f3);
            if(i==3) art.setImgid(R.drawable.f4);
            if(i==4) art.setImgid(R.drawable.f5);
            if(i==5) art.setImgid(R.drawable.f6);
            art.setTime("2017-4-1 15:16");
            art.setDescription("描述"+i);
            list.add(art);
        }
        return list;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initRecyclerView();
    }
}
